import {config} from '../config.js'

class HTTP {
  request(params){
    wx.request({
      url:params.type ? params.url:config.api_base_url+params.url,
      method: params.method,
      data:params.data,
      header:{
        'content-type': 'application/json',
        'appkey': config.appkey
      },
      success: (res)=>{
        res = res.data
        if(res.error_code == '0000') {
          params.success(res)
        } else {
          wx.showToast({
            title: res.msg,
            icon:'none'
          })
        }
      },
      fail: (err)=>{
        console.log(err)
        wx.showToast({
          title:'fail',
          icon:'none',
          duration:2000
        })
      }
    })
  }
}
export {HTTP}